<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta charset="utf-8" />
	<title></title>
	<link href="../css/bootstrap.min.css" rel="stylesheet">
	<link href="../css/bootstrap-select.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/bootstrap-datetimepicker.min.css">
	<link href="../css/font-awesome.min.css" rel="stylesheet">
	<link href="../css/JyyCommon.css" rel="stylesheet">
	<link href="../css/JyyTable.css" rel="stylesheet">
	<link href="../css/JyyTree.css" rel="stylesheet">
	<link href="../css/JyyMsgBox.css" rel="stylesheet">
	<link rel="stylesheet" href="../layui/css/layui.css">
	<link type="text/css" href="../css/ystep.css" rel="Stylesheet" />
	<script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
	<script type="text/javascript" src="../js/jquery.form.min.js"></script> 
	<script type="text/javascript" src="../js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-paginator.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-select.js"></script>
	<script type="text/javascript" src="../js/jyy_modal.js"></script>
	<script type="text/javascript" src="../js/JyyCommon.js"></script>
	<script type="text/javascript" src="../js/JyyTable.js"></script>
	<script type="text/javascript" src="../js/JyyTree.js"></script>
	<script type="text/javascript" src="../js/JyyMsgBox.js"></script>
	<script type="text/javascript" src="../js/JyyLoading.js"></script>
	<script type="text/javascript" src="../js/ystep.js" ></script>
	<script src="../layui/layui.js"></script>
    <script type="text/javascript" src="../../utils/CommonUtil.js"></script>
	<style>
	.heidenbt{
		display: none
	}
	.ystep-lg li {
	    width: 180px;
	}
	.layui-elem-field legend {
	    margin-left: 0px;
	    padding: 0 10px;
	    font-size: 22px;
	    font-weight: 400;
	}
	.layui-field-title {
	    margin: 0px 0px 2px;
	    border-width: 0px 0px 0px;
	}
	.tableA {
			cursor: pointer;
		}
		a {
	    color: #4090E7;
	    text-decoration: none;
	}
	.clickChangeDiv {
		width: 100%;
		height: 16px;
	}
	.tdinput {
		width: calc(100% - 20px);
	}
	.sort {
		color:#F59A23;
		cursor: pointer;
		margin-left: 5px;
		text-decoration: none;
		font-size: 14px;
	}
	.sort:hover {
		color:#F59A23;
		text-decoration: none;
	}
</style>
	<script type="text/javascript">
		var tree = null;
		var table = null;
		var scheme = null;
		var treeCode = null;
		var unitid =[];
		var zoneid =[];
		var zonename =[];
        let baseURL = localStorage.getItem("baseURL");
		$(function(){
			//scheme = parent.getSelectScheme();
			//加载树组件
			var sys = 1;
			//var modelId = getQueryString("modelId")||'88888888888';
			invoke_sys('getMenutree', {sys:sys,pagestype:'1000',planId:'0'}, function(data){
				var treeData = data.respData.jsonOutput;
				tree = RxTree.init("tree", treeData, {listMode:"tree",draggable:true,checkType:"single", drillType:"1"}, {width:"200px", bottom:"0px", top:"0px", border:"none",borderRight: "1px solid #e0e0e0"}, onTreeEvent);
				tree.expandAll();
				tree.checkNode("100", true);
				$("#tree").css("top","40px");
				$("#progressState").loadStep({
					size: "morelarge",
			      	color: "blue",
			      	steps: [
			      		{title: "解析",content: "数据解析"},
			      		{title: "转换",content: "数据转换"},
			      		{title: "入库",content: "数据入库"}
			      	]
			    });
				$.ajax({
					dataType: "json",
					async:true,
					data:{"projectid":parent.planId},
					url: "page/pageInfo/102/type"
				}).done(function(data) {
					var content = '';
					$.each(data,function(i,n){
						content += "<option value='" + n.CODE + "'>"+ n.NAME+"</option>";
					});
					$("#type").append(content);
				});
				
				$('.DivClose').click(function(){
					hidemodel();
				});
		    });
			/*var treeData = getTreeData();
			tree = RxTree.init("tree", treeData, {listMode:"tree",draggable:true,checkType:"single", drillType:"1"}, {width:"200px", bottom:"0px", top:"0px", border:"none",borderRight: "1px solid #e0e0e0"}, onTreeEvent);
			tree.expand(200);
			tree.expand(210);
			tree.checkNode("100", true);
			$("#tree").css("top","40px");*/

		})
		
		function onTreeEvent(event){
			console.log("onTreeEvent");
			if(event.name == "onclick"){
				if($("#xianshi").text() == "隐藏默认列") {
					colsState($("#xianshi"));
				}
				hidemodel();
				var data = event.node.data;
				if(data.isLeaf){
					if(data.code == "201"){
						$("#allDownload").click();
					}else if(data.code == "202"){
						//再次修改input内容
                        var form = $("#form2");
                        form.attr("action", baseURL+"page/pageInfo/202");
                        form.find("input").val(parent.planId);
                        formSubmit(document.querySelector('#form2'), "运行模拟数据-"+new Date().toLocaleDateString());
                        form.submit();
					}else if (data.code == "203"){
						window.modal = jyyModal.open("converExcel.html", {width:450, height:520, title:"dat导入"}, function(){
						    $("#progressState").setStep(1);
							parent.$('#tabsDivD').css('display','block');
							$('#divBpaFile > label').html('<span class="text-danger">*</span>潮流文件->运行模拟数据');
							$("#closeDiv").on("click", function(){
								window.modal.close();
								parent.$('#tabsDivD').css('display','none');
							});
							$("#convertExcel").text("数 据 转 换");
							$("#divSwiFile").remove();
							//$("#divVoltValue").show();
							$("#divParsePart").show();
							$("#divVoltGeog").show();
							$("#divDate1").show();
							$("#divGenParams").show();
							$('#date1').datetimepicker({
						        format:"yyyy",minView:4,startView:4,autoclose:1
						    });
							$('#date1').datetimepicker('update', new Date());
							$('.selectpicker').selectpicker({
			                    noneSelectedText: '请选择'
			                });
							$('input[type=radio][name=mapping]').change(function() {
								if (this.value == '0') {
									$("#firstMappGroup").attr("disabled", true);
								} else if (this.value == '1') {
									$("#firstMappGroup").attr("disabled", false);
								}
							});
							$.ajax({
								url: "page/pageInfo/getFirstGroup",
								dataType: "json",
								async:true,
								success : function(data) {
									var select = $("#firstMappGroup");
									var select1 = $("#secondMappGroup");
									for (var i = 0; i < data.respData.first.length; i++) {
										select.append("<option value='"+data.respData.first[i].ID+"'>"
												+ data.respData.first[i].NAME + "</option>");
									}
									for (var i = 0; i < data.respData.second.length; i++) {
										select1.append("<option value='"+data.respData.second[i].ID+"'>"
												+ data.respData.second[i].NAME + "</option>");
									}
									$('.selectpicker').selectpicker('val', '');
									$('.selectpicker').selectpicker('refresh');
								}
							});
							/* var Endday =  "2050-01-01";
							$('#date2').datetimepicker('update', Endday); */
							$("#convertExcel").on("click", function(){
								$.ajax({
						            dataType: "json",
									data:{planId:parent.planId},
									url: 'executivedat/getDatRunning'
						        }).done(function(res) {
						        	if(!res){
										var iyear = $("#date1").data("datetimepicker").getDate().getFullYear();
										var fileInput = $('#bpa').get(0).files[0];
										var parsePart = $('#parsePart').val();
										var voltSimple = $('#voltSimple').val();
										var geogMap = $('input[type=radio][name=geoMap]:checked').val();
										var ifGroup = $('input[type=radio][name=mapping]:checked').val();
										var firstGroup = $('#firstMappGroup').val();
										var secondGroup = $('#secondMappGroup').val();
										var suffix = fileInput==null?"":fileInput.name.substring(fileInput.name.lastIndexOf(".")+1, fileInput.name.length);
								    	
										if(JyyCommon.isEmpty(iyear)){
											JyyMsgBox.alert({ title:"警告", message:"规划年份不能为空!",type:"info"}).on(function (e) {});
										}else if(!fileInput || typeof(fileInput)=="undefined" || fileInput==null || fileInput=="undefined"){
											JyyMsgBox.alert({ title:"警告", message:"上传文件不能为空!",type:"info"}).on(function (e) {});
										}else if(suffix.toUpperCase() != "DAT"){
											JyyMsgBox.alert({ title:"警告", message:"请选择DAT文件!",type:"info"}).on(function (e) {});
										}else if(ifGroup == '1' && JyyCommon.isEmpty(firstGroup)){
											JyyMsgBox.alert({ title:"警告", message:"请选择映射分组!",type:"info"}).on(function (e) {});
										}else if(JyyCommon.isEmpty(secondGroup)){
											JyyMsgBox.alert({ title:"警告", message:"请选择次优分组!",type:"info"}).on(function (e) {});
										}else{
											//$("#versionidForC").val(jyyMain.selectScheme.code);
											$("#projectid").val(parent.planId);
											$("#iYear").val(iyear);
											$("#geogMap").val(geogMap);
											$("#ifGroup").val(ifGroup);
											$("#firstGroup").val(firstGroup);
											$("#secondGroup").val(secondGroup);
											$("#from").val("yxsjdr");
											//JyyLoading.start({loadingTips: "正在执行程序，请稍候..."});
											
											$("#"+window.modal.id).hide();
											//展示进度窗口
											
										    $('#wizardMask').show();
											$('#progressDiv').show();
											$('#progressDiv').draggable();
											$("#wizardMask").css("z-index","1002");
											$("#progressDiv").css("z-index","1003");
											var lasttext = ""; // 记录最后的文本
											//循环查看状态
										    var t = setInterval(function(){
										    	$.ajax({
										            dataType: "json",
													data:{planId:parent.planId},
													url: 'executivedat/getProgressInfo'
										        }).done(function(res) {
										        	var r = eval("("+res.result+")");
										        	/* $('#progressStrip').css({width:r.progressBar+"%"});
										        	$('#progressStrip').find("span").text(r.progressBar + "%"); */
										        	$('#progressText').html(r.result);
										        	if(r.result != "") lasttext = r.result;
										        	$('#progressText')[0].scrollTop = $('#progressText')[0].scrollHeight;
										        	$("#progressState").setStep(r.progressState);
										    	});
										    }, 1000); 
											$("#convertForm").ajaxSubmit({
                                                url: "executivedat/datImport",
												success : function(data) {
													window.modal.close();
													clearInterval(t);
						                            //parent.$('#tabsDivD').css('display','none');
										        	//$('#wizardMask').hide();
										    		//$('#progressDiv').hide();
													//tree.checkNode(treeCode, true);
										    		//parent.onMenuClick(0);
										    		$('#progressText').html(lasttext);
												}
											});
										    $('#progressClose').click(function(){
										    	layui.use('layer', function(){ //独立版的layer无需执行这一句
												  var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
												  
												  layer.confirm('是否确定结束计算？', {
													  btn: ['确定','取消'] //按钮
													}, function(){
														killNowTask();
														layer.msg('终止转换', {icon: 1});
														clearInterval(t);
														window.modal.close();
														$('#progressDiv').hide();
														$('#wizardMask').hide();
							                            parent.$('#tabsDivD').css('display','none');
														tree.checkNode(treeCode, true);
											    		parent.onMenuClick(0);
													}, function(){
														layer.close();
													});
												});
											});
										}
									} else {
										JyyMsgBox.alert({ title:"警告", message:"当前用户正在dat导入!",type:"info"}).on(function (e) {});
									}
						    	});
							});
						});
					}else if (data.code == "210503"){
						$('#sampleIframe').attr('src','energyStorage.html?projectId='+parent.planId);
						$('#sampleIframe').attr('src', $('#sampleIframe').attr('src'));
						$("#table").css("display","none");
						$("#operate").css("display","none");
						$("#iframe").css("display","block");
					} else{
						$("#table").css("display","block");
						$("#operate").css("display","block");
						$("#iframe").css("display","none");
						$("#term").val("");
						$("#type option:first").prop("selected", 'selected');
						treeCode = data.code;
						if(treeCode=='2102'){
							treeCode = '108';
						}
						if(treeCode=='2103'){
							treeCode = '112';
						}
						if(treeCode=='2104'){
							treeCode = '132';
						}
						setlabel(data.code);
						JyyLoading.start();
						$.when(getTableData(treeCode)).done(function(tableData){
							if(table == null){
								table = JyyTable.init("table", tableData, {position:"absolute",top:"50px",left:"205px",right:"5px",bottom:"0px",overflow:"hidden"}, onTableEvent);
							}else{
								table.refresh(tableData);
							}
							sortCol(treeCode);
							JyyLoading.end();
						});
					}
				} else if(data.code == "100") {
					$('#sampleIframe').attr('src','dataSourceHome.html?projectId='+parent.planId);
					$('#sampleIframe').attr('src', $('#sampleIframe').attr('src'));
					$("#table").css("display","none");
					$("#operate").css("display","none");
					$("#iframe").css("display","block");
					tree.expand(100);
				}
			}
		}
		function sortCol(code) {
			if(code != "102") return;
			var col = $("#jyytable_title tr:first").find("td:eq(1)").html();
			var sort = "<a onclick='seqSort(1);' class='sort'>▲</a><a onclick='seqSort(-1);' class='sort'>▼</a>";
			$("#jyytable_title tr:first").find("td:eq(1)").html(col+sort);
			
		}
		// 排序
		function seqSort(sort) {
			$.when(getTableDataSort(sort)).done(function(tableData){
				table.refresh(tableData);
				sortCol(treeCode);
				JyyLoading.end();
			});
		}
		function getTableDataSort(sort) {
			var defer = $.Deferred();
			var result = null;

			var pageSize = table.config.page.option.pageSize;
			$.ajax({
				dataType: "json",
				async:true,
				data:{"pagenow":1,"pagenum":pageSize,"keyword":$("#term").val(),"projectid":parent.planId, "type":$("#type").val(),"sort":sort},
				url: "page/pageInfo/" + treeCode
			}).done(function(res) {
				var sts=eval("("+res.respData+")");
				result = sts;
				defer.resolve(sts);
			});
			return defer.promise();
		}
		function setlabel(code){
			$("#daochu").addClass("heidenbt")
			$("#daoru").addClass("heidenbt")
			$("#xinzeng").addClass("heidenbt")
			$("#pichuli").addClass("heidenbt")
			$("#shanchu").addClass("heidenbt")
			$("#xianshi").addClass("heidenbt")
			$("#typeDiv").addClass("heidenbt")
			$("#selectName").addClass("heidenbt")
			$("#zrdx").addClass("heidenbt")
			$("#zrgl").addClass("heidenbt")
			$("#zrdxz").addClass("heidenbt")
			$("#intitOtherPower").addClass("heidenbt")
			$("#zrdxfh").addClass("heidenbt")
			$("#gengx").addClass("heidenbt")
			$("#xiugai").removeClass("heidenbt")
			$("#quxiao").removeClass("heidenbt")
			$("#baocun").removeClass("heidenbt")
			$("#calcul").addClass("heidenbt")
			$("#gengxin").addClass("heidenbt")
			$("#select").removeClass("heidenbt")
			$("#reset").removeClass("heidenbt")
			$("#term").removeClass("heidenbt")
			$("#searchName").removeClass("heidenbt")
			
			var label = "";
			if(code == "102"){
				$("#xianshi").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				$("#typeDiv").removeClass("heidenbt")
				$("#selectName").removeClass("heidenbt")
				label = "机组名称";
			}else if(code == "128"){
				$("#xianshi").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "线路名称";
			}else if(code == "109"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "风区1名称";
			}else if(code == "108"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "风区名称";
			}else if(code == "107"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "风电场名称";
			}else if(code == "113"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "光区1名称";
			}else if(code == "112"){
				$("#xianshi").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "光区名称";
			}else if(code == "111"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "光伏名称";
			}else if(code == "117"){
				$("#xianshi").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "节点名称";
			}else if(code == "126"){
				$("#shanchu").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "断面名称";
			}else if(code == "127"){
				$("#pichuli").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
				$("#xiugai").addClass("heidenbt")
				$("#quxiao").addClass("heidenbt")
				$("#baocun").addClass("heidenbt")
				label = "断面名称";
			}else if(code == "129"){
				$("#shanchu").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				label = "断面名称";
			}else if(code == "132"){
				label = "区域名称";
				$("#pichuli").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
				$("#xiugai").addClass("heidenbt")
				$("#quxiao").addClass("heidenbt")
				$("#baocun").addClass("heidenbt")
			}else if(code == "104"){
				$("#shanchu").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
			}else if(code == "122"){
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
			}else if(code == "123"){
				$("#pichuli").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
				$("#xiugai").addClass("heidenbt")
				$("#quxiao").addClass("heidenbt")
				$("#baocun").addClass("heidenbt")
				label = "机组名称";
			}else if(code == "124"){
				$("#shanchu").removeClass("heidenbt")
				$("#xinzeng").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
			}else if(code == "2102"){
				$("#shanchu").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				$("#zrdx").removeClass("heidenbt")
				$("#zrgl").removeClass("heidenbt")
				$("#zrdx").text('载入典型风区');
				$("#zrgl").text('风机风区关联');
				label = "风区名称";
			}
			else if(code == "2103"){
				$("#shanchu").removeClass("heidenbt")
				$("#daochu").removeClass("heidenbt")
				$("#daoru").removeClass("heidenbt")
				$("#zrdx").removeClass("heidenbt")
				$("#zrgl").removeClass("heidenbt")
				$("#xianshi").removeClass("heidenbt")
				$("#zrdx").text('载入典型光区');
				$("#zrgl").text('光伏光区关联');
				label = "光伏名称";
			}
			else if(code == "2104"){
				$("#pichuli").removeClass("heidenbt")
				$("#shanchu").removeClass("heidenbt")
				$("#xiugai").addClass("heidenbt")
				$("#quxiao").addClass("heidenbt")
				$("#baocun").addClass("heidenbt")
				$("#zrdxfh").removeClass("heidenbt")
				label = "区域名称";
			}
			else if(code == "2101"){
				$("#shanchu").removeClass("heidenbt")
				$("#zrdxz").removeClass("heidenbt")
				$("#gengx").removeClass("heidenbt")
				label = "区外电源";
			} else if(code == "210501" || code == "210502") {
				$("#calcul").removeClass("heidenbt")
				$("#gengxin").removeClass("heidenbt")
				$("#term").addClass("heidenbt")
				$("#searchName").addClass("heidenbt")
				$("#xiugai").addClass("heidenbt")
				$("#quxiao").addClass("heidenbt")
				$("#baocun").addClass("heidenbt")
				$("#select").addClass("heidenbt")
				$("#reset").addClass("heidenbt")
			}else if(code == "2111"){
				$("#xianshi").removeClass("heidenbt")
				$("#typeDiv").removeClass("heidenbt")
				$("#intitOtherPower").removeClass("heidenbt")
				$("#selectName").removeClass("heidenbt")
				label = "机组名称";
			}
			$("#searchName").text(label);
		}
		
		function onTableEvent(type, value){
			console.log("onTableEvent");
			var code = tree.getSelectData().code;
			if(treeCode=='2102'){
				treeCode = '108';
				code = '108';
			}
			if(treeCode=='2103'){
				treeCode = '112';
				code = '112';
			}
			if(treeCode=='2104'){
				treeCode = '132';
				code = '132';
			}
			if(type == "insertBefore"){
				console.log("insertBefore");
				//核查数据正确性
				for(var a = 0 ; a < value[1].length; a++){
					if(table.config.hideCols.indexOf(a) <= -1){
						if(JyyCommon.isEmpty(value[1][a])){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不可为空",type:"warning"}).on(function (e) {});
							return false;
						}else if((!JyyCommon.isObject(value[1][a]) && value[1][a].indexOf("请选择")>-1) || value[1][a] == " "){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]下拉框未做选择",type:"warning"}).on(function (e) {});
							return false;
						}else if(JyyCommon.isObject(value[1][a]) && JyyCommon.isEmpty(value[1][a].name)){
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不可为空",type:"warning"}).on(function (e) {});
							return false;
						} else if(treeCode=="2101" && a==8 && (value[1][a]>1 || value[1][a] < 0)) {
							JyyMsgBox.alert({ title:"警告", message:"["+table.config.data[0][a-1].name+"]不在在0-1之间",type:"warning"}).on(function (e) {});
							return false;
						}
					}
				}
				return true;
			} else if(type == "data"){
				if(code=='2102'){
					code = '108';
				}
				if(code=='2103'){
					code = '112';
				}
				if(code=='2104'){
					code = '132';
				}
				JyyLoading.start();
 				 $.ajax({
		            type:"POST",
		            url:"page/check/"+code,
		            data:{"value":JSON.stringify(value),"projectid":parent.planId,"unitid":unitid},
		      //      contentType:"application/json", 
		            success:function(data){
		            	var pageSize = table.config.page.option.pageSize;
		            	var currentPage = table.config.page.option.currentPage;
		    			if(code == 102) {
							$.when(getTableData(code, currentPage, pageSize, $("#term").val(), $("#type").val())).done(function(tableData){
								table.refresh(tableData);
								sortCol(treeCode);
								JyyLoading.end();
							});
		    			} else {
							$.when(getTableData(code, currentPage, pageSize, $("#term").val())).done(function(tableData){
								table.refresh(tableData);
		    					if(code == 117) {
		    						var i = $("#xianshi").find('i');
		    						if($(i).is('.glyphicon-align-justify')){
		   								table.config.hideCols = [5,6,7,8,9,10,11];
		   								table.hideCols(true);
		    						}else{
		    							table.hideCols(false);
		   								table.config.hideCols = [11];
		   								table.hideCols(true);
		    						}
		    					}
								JyyLoading.end();
							});
		    			}
		            }
		        }); 
			} else if(type == "page"){
				console.log("page");
				var val = $("#term").val();
				var code = tree.getSelectData().code;
				if(code=='2102'){
					code = '108';
				}
				if(code=='2103'){
					code = '112';
				}
				if(code=='2104'){
					code = '132';
				}
				JyyLoading.start();
    			if(code == 102) {
    				$.when(getTableData(code, value.currentPage, value.pageSize, val, $("#type").val())).done(function(tableData){
    					table.refresh(tableData);
						sortCol(treeCode);
    					JyyLoading.end();
    				});
    			} else {
    				$.when(getTableData(code, value.currentPage, value.pageSize, val)).done(function(tableData){
    					table.refresh(tableData);
    					if(code == 117) {
    						var i = $("#xianshi").find('i');
    						if($(i).is('.glyphicon-align-justify')){
   								table.config.hideCols = [5,6,7,8,9,10,11];
   								table.hideCols(true);
    						}else{
    							table.hideCols(false);
   								table.config.hideCols = [11];
   								table.hideCols(true);
    						}
    					}
    					JyyLoading.end();
    				});
    			}
			}
		}
		//新增按钮
		function addRow(){
			table.addRow();
		}
		//修改按钮
		function updateRow(){
			table.updateRows();
		}
		//取消修改按钮
		function cancelRow(){
			table.cancelRow();
		}
		//删除按钮
		function deleteRow(){
			table.deleteRows();
		}
		//保存按钮
		function saveRow(){
			table.saveRow();
		}
		//下载按钮
		function download(){
			var form = $('<form action="pageExcel/downloadExcel/'+ treeCode +'" style="display:none" method="post">');
			var input = $('<input type="hidden" name="projectid">');
		//	var iframe = $('<iframe name="downloadIframe" type="hidden">');
			input.attr("value",parent.planId);
			form.append(input);
		//	iframe.contents().find('body').append(form)
			$("body").append(form);
			form.submit();
			//iframe.remove();
			form.remove();
		}
		//上传按钮
		function upload(){
			var file = document.getElementById("file");
			if(file.value == ""){
				return;
			}
			JyyLoading.start();
			var fileObj = file.files[0];
			var url = "pageExcel/loadExcel/"+treeCode;

			var form = new FormData();
			form.append("file",fileObj);
			form.append("schemeid",parent.planId);
			var xhr = new XMLHttpRequest();
			xhr.open("post", url, true);
			xhr.send(form);
			xhr.onreadystatechange = function(){
			    if(xhr.readyState === 4 && xhr.status === 200){
					$.when(getTableData(treeCode)).done(function(tableData){
						$("#term").val("");
						$("#type option:first").prop("selected", 'selected');
						table.refresh(tableData);
						sortCol(treeCode);
    					if(treeCode == 117) {
    						var i = $("#xianshi").find('i');
    						if($(i).is('.glyphicon-align-justify')){
   								table.config.hideCols = [5,6,7,8,9,10,11];
   								table.hideCols(true);
    						}else{
    							table.hideCols(false);
   								table.config.hideCols = [11];
   								table.hideCols(true);
    						}
    					}
						JyyLoading.end();
					   	document.getElementById("file").value=null
					});
			    }
			}

		}
		//全量上传事件
		function allDownloads(event){
			if(event.value == ""){
				return;
			}
			JyyLoading.start();
			$("#form1").find("input[name='schemeid']").val(parent.planId);
			$("#form1").ajaxSubmit({
                url: "page/pageInfo/201",
				success : function(data) {
					alert(data);
					location.reload();
				}
			});
		}
		//显示隐藏列按钮
		function colsState(e){
			var i = $(e).find('i');
			if($(i).is('.glyphicon-align-justify')){
				$(i).removeClass('glyphicon-align-justify')
				$(i).addClass('glyphicon-list');
				$(e).html($(e).html().replace("显示隐藏列", "隐藏默认列"));
				table.hideCols(false);
				if(treeCode == "117") {
					table.config.hideCols = [11];
					table.hideCols(true);
				}
			}else{
				$(i).removeClass('glyphicon-list')
				$(i).addClass('glyphicon-align-justify');
				$(e).html($(e).html().replace("隐藏默认列", "显示隐藏列"));
				table.hideCols(true);
				if(treeCode == "117") {
					table.config.hideCols = [5,6,7,8,9,10,11];
					table.hideCols(true);
				}
			}
		}
		//查询
		function select(){
			
			var value = $("#term").val();
			
			var code = tree.getSelectData().code;
			if(code=='2102'){
				code = '108';
			}
			if(code=='2103'){
				code = '112';
			}
			if(code=='2104'){
				code = '132';
			}
			//var currentPage = table.config.page.option.currentPage;
			var currentPage = 1;
			var pageSize = table.config.page.option.pageSize;
			
			JyyLoading.start();
			if(code == 102||code == 2111) {
				$.when(getTableData(code, currentPage, pageSize, value, $("#type").val())).done(function(tableData){
					table.refresh(tableData);
					sortCol(treeCode);
					JyyLoading.end();
				});
			} else {
				$.when(getTableData(code, currentPage, pageSize, value, null)).done(function(tableData){
					table.refresh(tableData);
					if(code == 117) {
						var i = $("#xianshi").find('i');
						if($(i).is('.glyphicon-align-justify')){
								table.config.hideCols = [5,6,7,8,9,10,11];
								table.hideCols(true);
						}else{
							table.hideCols(false);
								table.config.hideCols = [11];
								table.hideCols(true);
						}
					}
					JyyLoading.end();
				});
			}
		}
		//重置
		function reset(){
			
			$("#term").val("");
			$("#type option:first").prop("selected", 'selected');
			
		//	var currentPage = table.config.page.option.currentPage;
			var currentPage = 1;
			var pageSize = table.config.page.option.pageSize;
			
			JyyLoading.start();
			$.when(getTableData(treeCode, currentPage, pageSize, null, null)).done(function(tableData){
				table.refresh(tableData);
				sortCol(treeCode);
				if(treeCode == 117) {
					var i = $("#xianshi").find('i');
					if($(i).is('.glyphicon-align-justify')){
							table.config.hideCols = [5,6,7,8,9,10,11];
							table.hideCols(true);
					}else{
						table.hideCols(false);
							table.config.hideCols = [11];
							table.hideCols(true);
					}
				}
				JyyLoading.end();
			});
		}
		
		function jumpToTree(code) {
			tree.expand(code);
			tree.checkNode(code, true);
		}
		
		function getTreeData(){
			return [
				{code:"200",name:"数据批处理",draggable:false,level:1,items:[
					{code:"201",name:"excel全量导入",isLeaf:true,draggable:false,items:[]},
					{code:"202",name:"excel全量导出",isLeaf:true,draggable:false,items:[]},
					{code:"210",name:"基于PSDB建立方案",draggable:false,items:[
						{code:"203",name:"DAT转换导入",isLeaf:true,draggable:false,items:[]},
						{code:"2101",name:"区外电源配置",isLeaf:true,draggable:false,items:[]},
						{code:"2111",name:"其他电源配置",isLeaf:true,draggable:false,items:[]},
						{code:"2102",name:"风区配置",isLeaf:true,draggable:false,items:[]},
						{code:"2103",name:"光区配置",isLeaf:true,draggable:false,items:[]},
						{code:"2104",name:"负荷配置",isLeaf:true,draggable:false,items:[]},
						{code:"2105",name:"风光储容量修正",draggable:false,items:[
							{code:"210501",name:"风电修正",isLeaf:true,draggable:false,items:[]},
							{code:"210502",name:"光伏修正",isLeaf:true,draggable:false,items:[]},
							{code:"210503",name:"储能修正",isLeaf:true,draggable:false,items:[]},
						]}
					]},
				]},
				{
					code:"100",name:"数据维护",draggable:true,level:1,
					items:[{
						code:"300",name:"节点信息",draggable:false,level:2,
						items:[	{code:"117",name:"节点",isLeaf:true,draggable:false,items:[]}]
					},{
						code:"400",name:"机组信息",draggable:false,level:2,
						items:[	{code:"102",name:"机组",isLeaf:true,draggable:false,items:[]},
								{code:"104",name:"水电三段式出力",isLeaf:true,draggable:false,items:[]},
								{code:"123",name:"机组指定出力",isLeaf:true,draggable:false,items:[]},
								{code:"124",name:"机组指定状态",isLeaf:true,draggable:false,items:[]},
								{code:"122",name:"机组报价",isLeaf:true,draggable:false,items:[]}]
					},{
						code:"500",name:"风电信息",draggable:false,level:2,
						items:[	{code:"108",name:"风区信息",isLeaf:true,draggable:false,items:[]},
								{code:"107",name:"风电场",isLeaf:true,draggable:false,items:[]},
								{code:"109",name:"风区之间相关系数",isLeaf:true,draggable:false,items:[]}]
					},{
						code:"600",name:"光伏信息",draggable:false,level:2,
						items:[	{code:"112",name:"光区信息",isLeaf:true,draggable:false,items:[]},
								{code:"111",name:"光伏电站",isLeaf:true,draggable:false,items:[]},
								{code:"113",name:"光区之间相关系数",isLeaf:true,draggable:false,items:[]}]
					},{
						code:"700",name:"线路断面信息",draggable:false,level:2,
						items:[	{code:"128",name:"线路",isLeaf:true,draggable:false,items:[]},
								{code:"126",name:"断面",isLeaf:true,draggable:false,items:[]},
								{code:"129",name:"断面线路包含关系",isLeaf:true,draggable:false,items:[]},
								{code:"127",name:"断面指定出力",isLeaf:true,draggable:false,items:[]}]
					},{
						code:"800",name:"负荷信息",draggable:false,level:2,
						items:[	{code:"132",name:"负荷曲线",isLeaf:true,draggable:false,items:[]}]
					}]
				}
				
			];
		}
		function  doSave_(){
			
			com.qh.goptcloud.RouteMap.prototype.doSave();
		};
		function getTableData(code, currentPage, pageSize, keyword, type){
			var defer = $.Deferred();
			var result = null;
			$.ajax({
				dataType: "json",
				async:true,
				data:{"pagenow":currentPage,"pagenum":pageSize,"keyword":keyword,"projectid":parent.planId,"type":type},
				url: "page/pageInfo/"+code
			}).done(function(res) {
				var sts=eval("("+res.respData+")");
				result = sts;
				defer.resolve(sts);
			});
			return defer.promise();
		}
		function killNowTask(taskid){
			var method ='killNowTask1';
			invoke(method, {modelId:100,taskid:taskid,planId:parent.planId}, function(data){
		    });
		}
		function invoke_sys(url, args, callback){
			var r, op = {
					url: 'Sysconfig/' + url,
					type:'POST',
					cache:false,
					async:true,
					dataType:'json',
					data:args ? JSON.stringify(args) : null,
					contentType:"application/json"
				};
			if(typeof callback == 'function'){
				op.success = function(data){
					if(data.error)return alert(data.error);
					callback(data);
				}
			} else {
				op.async = false;
				op.success = function(data){
					r = data
				};
			}
			$.ajax(op);
			if(r)if(r.error){
				alert(r.error);
				return null;
			}
			return r;
		};
		function invoke(url, args, callback){
			var r, op = {
					url: 'Sample/' + url,
					type:'POST',
					cache:false,
					async:true,
					dataType:'json',
					data:args ? JSON.stringify(args) : null,
					contentType:"application/json"
				};
			if(typeof callback == 'function'){
				op.success = function(data){
					if(data.error)return alert(data.error);
					callback(data);
				}
			} else {
				op.async = false;
				op.success = function(data){
					r = data
				};
			}
			$.ajax(op);
			if(r)if(r.error){
				alert(r.error);
				return null;
			}
			return r;
		}
		//载入典型
		function loadModel(){
			hidemodel();
			if(treeCode=='108'){
				$('#loadmodename').text('典型风区');
			}
			if(treeCode=='112'){
				$('#loadmodename').text('典型光区');
			}
			$('#loadDiv').show();
			$('#loadModel').empty();
			$('#modelList').empty();
			 var method ='getLoadModelByType';
				invoke(method, {modelType:treeCode}, function(data){
					$('#loadModel').empty();
					 var opt="<option value=' '>选择分组</option>";
					for(var i=0;i<data.length;i++){
						opt+='<option value='+data[i].groupid+'>'+data[i].groupname+'</option>';
					}
					 $("#loadModel").append(opt);
					 $("#loadModel").selectpicker('refresh');
			    });
			
		}
	//关联下拉
	function comEdit(){
		hidemodel();
		$('#loadDiv1').show();
		var textName = '';
		if(treeCode=='108'){
			$('#loadmodename1').text('风机-风区关联');
			textName='风';
		}
		if(treeCode=='112'){
			$('#loadmodename1').text('光伏-光区关联');
			textName='光';
		}
		 var optList="";
		 optList+="<option value=''>选择分区</option>";
           
		invoke('getUnitZoneByType', {modelType:treeCode,projectid:parent.planId}, function(data){
			for(var i=0;i<data.length;i++){
				optList+='<option value='+data[i].zoneid+'>'+data[i].zonename+'</option>';

			}
	  
			 optList+=" </select>";
			$('#tabs1').empty();
			invoke('getGroupUnitByType', {modelType:treeCode,projectid:parent.planId}, function(data){
				 var opt="";
					opt+="<table class='table table-hover'>";
					opt+="  <thead><tr><th style='width: 50%;' >"+textName+"机所属发电公司</th><th style='width: 50%;' >对应"+textName+"区</th></tr></thead>";
					opt+="   <tbody id='tbcomdata'>";

				for(var i=0;i<data.length;i++){
					var idcode = 'tabse'+i;
					 var optListH="<select id='"+idcode+"'  class='selectpicker show-tick form-control'  data-live-search='true' onchange='comChange(this)'>";
					opt+=" <tr><td><option value='"+data[i].companyid+"'>"+data[i].companyname+"</option></td><td>"+optListH+optList+"</td></tr>";
				}
				opt+="   </tbody>";
				opt+=" </table>";
				$("#tabs1").append(opt);
				for(var i=0;i<data.length;i++){
					$("#tabse"+i).selectpicker('refresh');
				}
			});
		});	
	}
	//风光关联选择
	function comChange(e){
		var zid = $("#"+e.id).val();
		var zname =$("#"+e.id).find("option:selected").text();
		var uid = $($($("#"+e.id).parent().parent().parent().children()[0]).children()[0]).val();
		unitid.push(uid);
		zoneid.push(zid);
		zonename.push(zname);
		
	};
	//风光典型分组
	function modelTable(obj){
		$('#modelList').empty();
		var method ='getGroupByType';
		invoke(method, {modelType:treeCode,groupid:obj.value}, function(data){
			var opt="";
			for(var i=0;i<data.length;i++){
				opt+="<li class='list-group-item'> <input type='checkbox' aria-label="+data[i].groupid+"> "+data[i].groupname+"</li>";
			}
			$("#modelList").append(opt);
			$("#checkAllBtn").click(function(){
				$("#modelList").find('li').each(function(e) {
					$(this).children()[0].checked = true;
		    	})
			});
			$("#checkNotBtn").click(function(){
				$("#modelList").find('li').each(function(e) {
					$(this).children()[0].checked = false;
		    	})
			});
	    });
	}
	//风光典型保存
	function insmodel(){
		var method ='SaveModelByType';
		var groupname =[];
		
		$('#modelList').find('li').each(function(e) {
			if($(this).children()[0].checked){
				groupname.push($(this).text());
			}
        })
        var loadModel = "";
		if(treeCode == "108" || treeCode == "112"){
			loadModel = $("#loadModel").val();
		}
        if(groupname.length>0){
			 invoke(method, {modelType:treeCode,groupname:groupname,projectid:parent.planId,loadModel:loadModel}, function(data){
				 $('#loadDiv').hide();
				 select();
		    }); 
        }
	}
	//风光关联保存
	function saveCom(){
		var method ='SaveModelUnitByType';
		 if(unitid.length>0){
			 invoke(method, {modelType:treeCode,unitid:unitid,projectid:parent.planId,zoneid:zoneid,zonename:zonename}, function(data){
				 $('#loadDiv1').hide();
				 select();
		    }); 
       };
		
	}
	//载入典型负荷
	function zrdxfh(){
		hidemodel();
		$('#loadmodename2').text('典型负荷');
		$('#loadDiv2').show();
		$('#loadzrdxfh').empty();
		var method ='getLoadModelByType';
		invoke(method, {modelType:treeCode}, function(data){
			$('#loadzrdxfh').empty();
			var opt="";
			for(var i=0;i<data.length;i++){
				opt+='<option value='+data[i].groupid+'>'+data[i].groupname+'</option>';
			}
			$("#loadzrdxfh").append(opt);
			$("#loadzrdxfh").selectpicker('refresh');
			modelzrdxfh($("#loadzrdxfh")[0]);
	    });
	}
	// 更新区外电源基础表数据
	function updateOut() {
		invoke("updateExternalSource", {projectid:parent.planId}, function(data){
			 select();
	    });
	}
	//典型负荷分组加载年份
	function modelzrdxfh(obj){
		$('#loadzrdxfhnf').empty();
		var method ='getGroupByYear';
		invoke(method, {modelType:treeCode,groupid:obj[obj.selectedIndex].value}, function(data){
			$('#loadzrdxfhnf').empty();
			var opt="<option value=''>选择年份</option>";
			for(var i=0;i<data.length;i++){
				opt+='<option value='+data[i].groupid+'>'+data[i].groupname+'</option>';
			}
			$("#loadzrdxfhnf").append(opt);
			$("#loadzrdxfhnf").selectpicker('refresh');
	    });
	}
	//载入典型负荷保存
	function savezrdxfh(){
		var method ='savezrdxfh';
		var nyear = $("#N_year").val();
		var groupid =$('#loadzrdxfh').val();
		var oldeyear =$('#loadzrdxfhnf').val();
		if(nyear && groupid && oldeyear){
			invoke(method, {groupid:groupid,oldeyear:oldeyear,nyear:nyear,projectid:parent.planId}, function(data){
				$('#loadDiv2').hide();
				select();
		    }); 
    	}else{
    	}
	}
	//关闭窗口
	function hidemodel(){
		$("#modelList").empty();
		$("#tabs3").empty();
		$("#tabs4").empty();
		$('#loadDiv').hide();
		$('#loadDiv1').hide();
		$('#loadDiv2').hide();
		$('#loadDiv3').hide();
		$('#loadDiv4').hide();
		unitid =[];
		zoneid =[];
		zonename =[];
	}
	//载入典型
	function zrdxz(){
		hidemodel();
		$('#loadDiv3').show();
	    $('#loadmodename3').text('典型机组');
        var optListData ="";
		invoke('getUnitZoneByType', {modelType:treeCode,projectid:parent.planId}, function(data){
			optListData = data.respData;
			
			$('#tabs3').empty();
			invoke('getUnitlist4data', {}, function(data){
				
				 var opt="";
					opt+="<table class='table table-hover'id='unitTable'>";
					opt+="  <thead><tr><th style='width: 25%;' ><input type='checkbox' id='checkAll'>区外电源</th><th style='width: 25%;' >选择出力类型</th><th style='width: 25%;' >区外节点</th><th style='width: 25%;' >连接主网节点</th></tr></thead>";
					opt+="   <tbody >";

				for(var i=0;i<data.respData.length;i++){
					 var optList="";
					for(var r=0;r<optListData.length;r++){
						if(data.respData[i].mainareaname==optListData[r].zonename){
							optList+='<option value='+optListData[r].zoneid+'  selected>'+optListData[r].zonename+'</option>';
						}else{
							optList+='<option value='+optListData[r].zoneid+'>'+optListData[r].zonename+'</option>';
						}
					}
					 optList+=" </select>";
					var idcode = 'units'+i;
					var idtype = 'unitsType'+i;
					var idout = 'outarea'+i;
					var unitTypelist="<select id='"+idtype+"'  class='selectpicker show-tick form-control'>";
						unitTypelist+='<option value=1>指定出力</option>';
						unitTypelist+='<option value=2>指定电量</option>';
						unitTypelist+='<option value=3>三段式出力</option>';
						unitTypelist+=" </select>";
					 var optListH="<select id='"+idcode+"'  class='selectpicker show-tick form-control'  data-live-search='true' >";
					//opt+=" <tr><td value='"+data[i].companyid+"'>"+data[i].companyname+"</td><td>"+optListH+optList+"</td></tr>";
					opt+=" <tr><td><input type='checkbox' name='unittypes' value='"+data.respData[i].unitname+"'>"+data.respData[i].unitname+"</td><td>"+unitTypelist+"</td><td id='"+idout+"'>"+data.respData[i].outareaname+"</td><td>"+optListH+optList+"</td></tr>";
				}
				opt+="   </tbody>";
				opt+=" </table>";
				$("#tabs3").append(opt);
				for(var i=0;i<data.respData.length;i++){
					$("#units"+i).selectpicker('refresh');
				 	$("#unitsType"+i).selectpicker('refresh');
				}
				$("#checkAll").click(function(){
					for(let i = 0; i < $("input[name=unittypes]").length; i++) {
		                $("input[name=unittypes]")[i].checked = this.checked;
		            }
				});
			});
		});	
	}
	//风光关联选择
	function unitZChange(e){
		var zid = $("#"+e.id).val();
		var zname =$("#"+e.id).find("option:selected").text();
		var uid = $($($("#"+e.id).parent().parent().parent().children()[0]).children()[0]).val();
		unitid.push(uid);
		zoneid.push(zid);
		zonename.push(zname);
	};
	//载入典型保存
	function savePower(){
		var mytable = document.getElementById('unitTable');
        var unit = [];
        var unittype = [];
        var unitzone = [];
        var unitname = [];
        var outareaname = [];
         var ks = document.getElementsByName('unittypes');
         for(var i=0;i<ks.length;i++){
        	 if(ks[i].checked){
        		 unit.push($(mytable.rows[i+1].cells[0].innerHTML)[0].value);
        		 unittype.push($('#unitsType'+i).find("option:selected").text());
        		 unitzone.push($('#units'+i).val());
        		 unitname.push($('#units'+i).find("option:selected").text());
        		 outareaname.push($('#outarea'+i).text());
        		 
        	 }
         }
         if(unit.length>0){
        	 var method ='SaveOutUnitCheck';
			 invoke(method, {projectid:parent.planId,unit:unit}, function(data){
				 if(data.flag){
				 	  method ='SaveOutUnit';
					 invoke(method, {projectid:parent.planId,unit:unit,unittype:unittype,unitzone:unitzone,unitname:unitname,outareaname:outareaname}, function(data){
						 $('#loadDiv3').hide();
						 select();
				    }); 
				 }else{
					 JyyMsgBox.alert({ title:"警告", message:"机组已经存在",type:"warning"}).on(function (e) {});
					 return false;
				 }
		    }); 
         }
		
	}
	function pageOnClick(e) {
		unitid = e.getAttribute("unitid");
		var type = e.getAttribute("groupid");
		$("#tabTitle").text(type);
		$('#tabsEditData').draggable();
		$('#tabsEditData').css('display','block');
		$('#contentPanel').attr('src','./mapDataPopup2.html?unitid=' + escape(unitid) + '&type=' + escape(type) + '&pgtype=' + escape(type));
	}
	function pageOnClick1(e) {
		var type = "";
		if(treeCode == "123") {
			type = "unit";
		} else if(treeCode == "127") {
			type = "section";
		} else if(treeCode == "132") {
			type = "load";
		}
		var curid = e.getAttribute("curid");
		var apptype = e.getAttribute("apptype");
		var curname = e.getAttribute("curname");
		$("#tabTitle").text(curname);
		$('#tabsEditData').draggable();
		$('#tabsEditData').css('display','block');
		$('#contentPanel').attr('src','./dataSourceOpen.html?curid=' + escape(curid) + '&curname=' + escape(curname) + '&apptype=' + escape(apptype) + '&type=' + escape(type));
	}
	function closeTabsEditData(){
		$('#tabsEditData').css('display','none');
		select();
	}
	function addOpen(){
		var type = "";
		if(treeCode == "123") {
			type = "unitedit";
		} else if(treeCode == "127") {
			type = "sectionedit";
		} else if(treeCode == "132") {
			type = "loadedit";
		}
		$("#tabTitle").text("批量维护");
		$('#tabsEditData').draggable();
		$('#tabsEditData').css('display','block');
		$('#contentPanel').attr('src','./dataSourceOpen.html?type=' + escape(type));
	}
	function toInput(e) {
		var companyid = e.getAttribute("companyid");
		if(companyid == "0") return;
		var text = $(e).text();
		if(text == "" && $(e).children().length != 0) {
			text = $(e).children().val();
		} 
		var input = "<input class='tdinput' id='input"+companyid+"' onblur='toChange(this);' >";
		$(e).html(input);
		$("#input"+companyid).keyup(function(){
	        this.value = this.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
	        this.value = this.value.replace(/^\./g,""); //验证第一个字符是数字
	        this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
	        this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");//限制"10.5." 这种情况
		});
		$("#input"+companyid).focus();
		$("#input"+companyid).val(text);
	}
	function toChange(e) {
		var parent = $(e).parent();
		parent.html($(e).val());
		var tabData = table.config.data;
		var rowIndex = parent.parent().parent('tr')[0].rowIndex;
		var cellIndex = parent.parent('td')[0].cellIndex;
		tabData[rowIndex][cellIndex] = "<div class='clickChangeDiv' onclick='toInput(this);' companyid='"+tabData[rowIndex][0]+"'>"+ $(e).val()+"</div>";
	}
	function calculation() {
		var tabData = table.config.data;
		for(var i = 1;i < tabData.length - 1;i++) {
			var cacul = $(tabData[i][3]).text();
			if(cacul=="" || cacul==0) continue;
			tabData[i][4] = cacul/tabData[i][2];
		}
		table.init();
	}
	function toUpdate() {
		JyyMsgBox.confirm({ title:"提示", message:"确定要更新数据？",type:"warning"}).on(function (e) {
			if (e) {
				var arr = [];
				var tabData = table.config.data;
				for(var i = 1;i < tabData.length - 1;i++) {
					if(tabData[i][4] == "") continue;
					arr.push({"companyid":tabData[i][0],"coeff":tabData[i][4]});
				}
				if(arr.length == 0) return;
				var type = 0;
				if(treeCode == "210501") {
					type = 11;
				} else if(treeCode == "210502") {
					type = 12;
				}
				invoke("updateCoeff", {projectid:parent.planId,coeff:arr,type:type}, function(data){
					if(data.flag) {
						select();
					} else {
						JyyMsgBox.alert({ title:"警告", message:"数据更新失败",type:"warning"}).on(function (e) {});
						return false;
					}
			    });
			}
		});
	}
	function intitOtherPower(){
		hidemodel();
		$('#loadDiv4').show();
	    $('#loadmodename4').text('典型机组');
	    $('#tabs14').empty();
   		var groupList = invoke('getOtherUnitGrouplist', {});
   		var groupId = '';
   	 	var rs = "<span style='width: 15%;'>选择分组：</span><select id='othergroup' class='selectpicker show-tick form-control' data-width='70%' data-live-search='true' onchange='reshGroupData(this.options[this.options.selectedIndex].value)'>";
		for(var r=0;r<groupList.length;r++){
			groupId = groupList[0].groupid;
			rs+='<option value='+groupList[r].groupid+'>'+groupList[r].groupname+'</option>';
		}
		rs+=" </select>";
		$("#tabs14").append(rs);
		$("#othergroup").selectpicker('refresh');
		
		reshGroupData(groupId)	
		
	};
	function reshGroupData(groupId){
		$('#tabs4').empty();
		var optListData ="";
		invoke('getUnitZoneByType', {modelType:treeCode,projectid:parent.planId}, function(data){
			optListData = data;
			invoke('getOtherUnitlist', {group_id:groupId,projectid:parent.planId}, function(data){
				
				 var opt="";
					opt+="<table class='table table-hover'id='unitTable1'>";
					opt+="  <thead><tr><th style='width: 25%;' ><input type='checkbox' id='checkAll'>电源名称</th><th style='width: 25%;' >所属节点</th><th style='width: 25%;' >机组类型</th><th style='width: 25%;' >装机容量</th></tr></thead>";
					opt+="   <tbody >";

				for(var i=0;i<data.length;i++){
					 var optList="";
					for(var r=0;r<optListData.length;r++){
						if(data[i].areaname==optListData[r].zonename){
							optList+='<option value='+optListData[r].zoneid+'  selected>'+optListData[r].zonename+'</option>';
						}else{
							optList+='<option value='+optListData[r].zoneid+'>'+optListData[r].zonename+'</option>';
						}
					}
					 optList+=" </select>";
					var idcode = 'Otherunits'+i;
					 var optListH="<select id='"+idcode+"' class='selectpicker dropdown show-tick form-control' data-size='5' data-dropup-auto='false' data-live-search='true' >";
					opt+=" <tr><td><input type='checkbox' name='Otherunittypes' value='"+data[i].unitname+"'>"+data[i].unitname+"</td><td>"+optListH+optList+"</td><td>"+data[i].unittype+"</td><td>"+data[i].unitcapamax+"</td></tr>";
				}
					opt+="   </tbody>";
					opt+=" </table>";
				 $("#tabs4").append(opt);
				   for(var i=0;i<data.length;i++){
				 		$("#Otherunits"+i).selectpicker('refresh');
					}
				$("#checkAll").click(function(){
					for(let i = 0; i < $("input[name=Otherunittypes]").length; i++) {
		                $("input[name=Otherunittypes]")[i].checked = this.checked;
		            }
				});
		    });
	  });	
	}
	//载入典型保存
	function saveOtherPower(){
		
		var mytable = document.getElementById('unitTable1');
        var unit = [];
         var ks = document.getElementsByName('Otherunittypes');
         for(var i=0;i<ks.length;i++){
        	 var obj ={};
        	 if(ks[i].checked){
        		 obj.unitname = $(mytable.rows[i+1].cells[0].innerHTML)[0].value;
        		 obj.nodeareaid =$('#Otherunits'+i).find("option:selected").val();
        		 obj.nodeareaname=$('#Otherunits'+i).find("option:selected").text();
        		 unit.push(obj);
        	 }
         }
         if(unit.length>0){
        	 var method ='SaveOtherUnit';
        	 var groupid = $('#othergroup').find("option:selected").val()
			 invoke(method, {projectid:parent.planId,unit:unit,groupid:groupid}, function(data){
				 $('#loadDiv4').hide();
				 select();
		    }); 
				 
         }
		
	}
	
	
	</script>
</head>
<body style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;">
	<div id="operate" style="position: absolute;top: 0px;left: 200px;right: 0px;height: 50px;">
		<div class="col-md-12" style="position: absolute;top: 10px;padding-left: 5px;padding-right: 5px;">
			
			<button id="pichuli" class="btn btn-info btn-sm" onclick=addOpen()><i class="fa fa-plus"></i>批量维护</button>
			<button id="xinzeng" class="btn btn-info btn-sm" onclick=addRow()><i class="fa fa-plus"></i>新增</button>
			<button id="xiugai"  class="btn btn-info btn-sm" onclick=updateRow()><i class="glyphicon glyphicon-pencil"></i>修改</button>
			<button id="quxiao"  class="btn btn-info btn-sm" onclick=cancelRow()><i class="glyphicon glyphicon-share-alt"></i>取消修改</button>
			<button id="shanchu"  class="btn btn-info btn-sm" onclick=deleteRow()><i class="glyphicon glyphicon-remove"></i>删除</button>
			<button id="baocun"  class="btn btn-info btn-sm" onclick=saveRow()><i class="glyphicon glyphicon-saved"></i>保存</button>
			<button id="daochu"  class="btn btn-info btn-sm" onclick=download()><i class="glyphicon glyphicon-download"></i>导出Excel</button>
			<button id="daoru"  class="btn btn-info btn-sm" onclick=$("#file").click();><i class="glyphicon glyphicon-upload"></i>导入Excel</button>
			<button id="xianshi"  class="btn btn-info btn-sm" onclick=colsState(this)><i class="glyphicon glyphicon-align-justify"></i>显示隐藏列</button>
			<button id="zrdx"  class="btn btn-info btn-sm" onclick=loadModel();><i class="glyphicon glyphicon-th-list"></i>载入典型风区</button>
			<button id="zrgl"  class="btn btn-info btn-sm" onclick=comEdit();><i class="glyphicon glyphicon-th-list"></i>风机风区关联</button>
			<button id="zrdxz"  class="btn btn-info btn-sm" onclick=zrdxz();><i class="glyphicon glyphicon-th-list"></i>载入典型值</button>
			<button id="intitOtherPower"  class="btn btn-info btn-sm" onclick=intitOtherPower();><i class="glyphicon glyphicon-th-list"></i>载入典型值</button>
			<button id="zrdxfh"  class="btn btn-info btn-sm" onclick=zrdxfh();><i class="glyphicon glyphicon-th-list"></i>载入典型负荷</button>
			<button id="gengx"  class="btn btn-info btn-sm" onclick=updateOut();><i class="glyphicon glyphicon-pencil"></i>更新</button>
			<button id="calcul"  class="btn btn-info btn-sm" onclick=calculation();><i class="glyphicon"></i>计算</button>
			<button id="gengxin"  class="btn btn-info btn-sm" onclick=toUpdate();><i class="glyphicon"></i>更新</button>
			<button id="reset" class="btn btn-info btn-sm" style="float: right;" onclick=reset()>重置</button>
			<button id="select" class="btn btn-info btn-sm" style="float: right;margin-right: 5px;" onclick=select()>查询</button>

			<div class="col-sm-3" style="float: right;width:170px;padding-left: 0px;">
            	<input id="term" type="text" class="form-control"style="width:150px;height:30px;font-size: 12px;" id="txt_search_departmentname">
            </div>
			<label id="searchName" class="control-label col-sm-1" style="float: right;margin-top: 7px;padding: 0px;width: 60px;font-weight: normal;" for="txt_search_departmentname"></label>
			
			<div id="typeDiv" class="col-sm-3 heidenbt" style="float: right;width:170px;padding-left: 0px;">
            	<select id="type" class="form-control" style="width:150px;height:30px;font-size: 12px;">
            		<option value="">全部</option>
            	</select>
            </div>
			<label id="selectName" class="control-label col-sm-1 heidenbt" style="float: right;margin-top: 7px;padding: 0px;width: 60px;font-weight: normal;">机组类型</label>
		
			<input type="file" id="file" name="file" onchange="upload(this)" style="display:none"/>
		</div>
	</div>
	<div id="tree"></div>
	<div id="table"></div>
	<div id="iframe" style="position: absolute;top: 0px;left: 200px;right: 0px;height: 100%;display:none">
		<iframe  frameborder="0" width="100%" scrolling="No" height="100%" leftmargin="0" topmargin="0" id="sampleIframe"></iframe>
	</div>
	<form action='page/pageInfo/201' method='post' id='form1' enctype="multipart/form-data">
		<input type="file" id="allDownload" name="allDownload" onchange="allDownloads(this)" style="display:none"/>
		<input type="hidden" name="schemeid">
	</form>
	<form action='page/pageInfo/202' method='post' id='form2' >
		<input type="hidden" name="schemeid">
	</form>
	<div id="wizardMask" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;background:#000000;filter:alpha(Opacity=60);opacity:0.6;overflow: hidden;display:none;"></div>
	<div id="progressDiv" class="ui-widget-content" style="position:absolute;top:10%;left:30%;width:510px;height:520px;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;">
		<div style="position:absolute;top:0px;left:0px;width:100%;height:60px;">
			<div style="position:absolute;top:0px;left:28px;width:120px;height:60px;line-height:60px;">DAT转换进程</div>
			<!-- <div id="progressMin" style="position:absolute;top:10px;right:28px;width:17px;height:17px;background:url(../images/dialog_min.png) no-repeat;cursor:pointer;"></div> -->
			<div id="progressClose" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
		</div>
		<div style="position: absolute;top: 50px;left:20px;width:450px;bottom:20px">
			<div id="progressState" style="position: absolute;top: 20px;left: 10px;right: 10px;"></div>
			<!-- <div style="position: absolute;top: 90px;left: 20px;right: 10px;">
				<div class="progress">
				  <div id="progressStrip" class="progress-bar progress-bar-striped progress-bar-info active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
				    <span></span>
				  </div>
				</div>
			</div> -->
			<div id="progressText" style="position: absolute;top: 100px;left: 20px;right: 10px;bottom: 0px;color: white;background: black;overflow-x: hidden;padding: 10px;"></div>
		</div>
	</div>
	<div id="tabsEditData" class="ui-widget-content" style="position:absolute;top: 8%;left: 15%;width: 80%;height: 500px;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;z-index: 9999;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
			<legend id="tabTitle"></legend>
				<div onclick="closeTabsEditData();" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
			</fieldset>
		<div class="ui-widget-content" style="position:absolute;top: 35px;left: 0%;border: 0px;width: 100%;height: 93%;background:#ffffff;overflow: auto;">
			<iframe id="contentPanel" src="" frameborder="0" width="100%" scrolling="No" height="99%" leftmargin="0" topmargin="0" ></iframe>
		</div>
	</div>
	
	<div id="loadDiv" class="ui-widget-content" style="position:absolute;top: 11%;left: 37%;width: 35%;height: 64%;min-width: 470px;min-height: 330px;z-index: 10000;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
			<legend id = "loadmodename" style="border: none;padding-top: 5px;margin-bottom: 15px;"></legend>
			<div class="DivClose" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
		</fieldset>
	  	<div class="form-group">
        	<label class="col-sm-3 control-label" style="margin-top: 4px;margin-left: 18px;">选择分组：</label>
        	<div class="col-sm-4">
            	<select id="loadModel" name="loadModel" class="selectpicker show-tick form-control"  data-live-search="true" onchange="modelTable(this)" >
                	<option value="">选择分组</option>
            	</select>
        	</div>
		</div>
               
		<ul id="modelList" class="list-group" style="width: 66%;height: 52%;overflow: auto;position: absolute;top: 30%;left: 10%;"></ul>
        <button class="btn btn-info btn-sm glyphicon" id="checkAllBtn" style="position: absolute;float: right;top: 30%;left:80%;">全选</button>
        <button class="btn btn-info btn-sm glyphicon" id="checkNotBtn" style="position: absolute;float: right;top: 42%;left:80%;">取消选中</button>
		<button class="btn btn-info btn-sm glyphicon glyphicon-ok-circle" style="position: absolute;float: right;margin: 0% 0% 0% -30%;top: 90%;" onclick=insmodel()>确定</button>
		<button class="btn btn-info btn-sm glyphicon glyphicon-remove-circle" style="position: absolute;float: right;margin: 0% 0% 0% -10%;top: 90%;" onclick=hidemodel()>取消</button>
	</div>
	<div id="loadDiv1" class="ui-widget-content" style="position:absolute;top: 11%;left: 37%;width: 35%;height: 64%;min-width: 470px;min-height: 330px;z-index: 10000;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
			<legend id = "loadmodename1" style="width: 49%;border: none;padding-top: 5px;margin-bottom: 5px;"></legend>
	  		<div class="DivClose" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
		</fieldset>
		<div id="tabs1" class="form-group" style="margin: 2% 4% 0% 4%;border-block: inherit;border-bottom: none;height: calc(100% - 100px);border:1px solid #ccc;overflow: auto;"></div>
        <div style="height: 50px;text-align: center;">
    		<button class="btn btn-info btn-sm glyphicon glyphicon-ok-circle" style="margin: 10px 30px 0 0;" onclick=saveCom()>确定</button>
         	<button class="btn btn-info btn-sm glyphicon glyphicon-remove-circle" style="margin: 10px 0 0 0;" onclick=hidemodel()>取消</button>
		</div> 
	</div>
	<div id="loadDiv2" class="ui-widget-content" style="position:absolute;top: 11%;left: 37%;width: 25%;height: 64%;min-width: 340px;min-height: 330px;z-index: 10000;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
			<legend id = "loadmodename2" style="border: none;padding-top: 5px;margin-bottom: 15px;"></legend>
	  		<div class="DivClose" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
		</fieldset>
        <div class="form-group" style="width: 100%;height: 10%">  
        	<label class="col-sm-3 control-label" style="margin-top: 4px;width: 150px;text-align: right;">负荷水平：</label>
            <div class="col-sm-4"  style="width: 180px;">
            	<select id="loadzrdxfh" name="loadzrdxfh" class="selectpicker show-tick form-control"  data-live-search="true" onchange="modelzrdxfh(this)">
                	<option value="">负荷水平</option>
                </select>
            </div>
		</div>
		<div class="form-group" style="width: 100%;height: 10%">  
        	<label class="col-sm-3 control-label" style="margin-top: 4px;width: 150px;text-align: right;">负荷水平内负荷年份：</label>
        	<div class="col-sm-4"  style="width: 180px;">
            	<select id="loadzrdxfhnf" name="loadzrdxfhnf" class="selectpicker show-tick form-control"  data-live-search="true">
                	<option value="">选择年份</option>
            	</select>
        	</div>
		</div>
		<div class="form-group" style="width: 100%;height: 10%">  
        	<label class="col-sm-3 control-label" style="margin-top: 4px;width: 150px;text-align: right;">写入年份：</label>
            <div class="col-sm-4"  style="width: 180px;">
            	<input id="N_year" type="text" class="form-control" >
            </div>
		</div>
		<button class="btn btn-info btn-sm glyphicon glyphicon-ok-circle" style="position: absolute;float: right;margin: 0% 0% 0% 33%;top: 90%;;" onclick=savezrdxfh()>确定</button>
        <button class="btn btn-info btn-sm glyphicon glyphicon-remove-circle" style="position: absolute;float: right;margin: 0% 0% 0% 66%;top: 90%;;" onclick=hidemodel()>取消</button>
	</div>
	<div id="loadDiv3" class="ui-widget-content" style="position:absolute;top: 11%;left: 37%;width: 35%;height: 64%;min-width: 470px;min-height: 330px;z-index: 10000;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px;">
			<legend id = "loadmodename3" style="width: 49%;border: none;padding-top: 5px;margin-bottom: 5px;"></legend>
	  		<div class="DivClose" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
		</fieldset>
		<div id="tabs3" class="form-group" style="margin: 2% 4% 0% 4%;border-block: inherit;border-bottom: none;height: calc(100% - 100px);border:1px solid #ccc;overflow: auto;"></div>
       	<div style="height: 50px;text-align: center;">
    		<button class="btn btn-info btn-sm glyphicon glyphicon-ok-circle" style="margin: 10px 30px 0 0;" onclick=savePower()>确定</button>
         	<button class="btn btn-info btn-sm glyphicon glyphicon-remove-circle" style="margin: 10px 0 0 0;" onclick=hidemodel()>取消</button>
		</div>
	</div>
	<div id="loadDiv4" class="ui-widget-content" style="position:absolute;top: 11%;left: 37%;width: 35%;height: 64%;min-width: 470px;min-height: 330px;z-index: 10000;background:#ffffff;overflow: hidden;border:1px solid #cccccc;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:none;">
			 <div class="layui-elem-field layui-field-title" style="margin-top: 0px;height: 40px;">
			 	<div id="loadmodename4" style="width: 49%;font-size: 16px;font-weight: bold;position: absolute;top:10px;left:20px;"></div>
	  			<div class="DivClose" style="position:absolute;top:10px;right:10px;width:17px;height:17px;background:url(../images/dialog_close.png) no-repeat;cursor:pointer;"></div>
			</div>
			<div id="tabs14" class="form-group" style="margin: 2% 4% 0% 4%;height: 10%;width:50%;"></div>
			<div id="tabs4" class="form-group" style="margin: 2% 4% 0% 4%;border-block: inherit;border-bottom: none;height: calc(90% - 110px);border:1px solid #ccc;overflow: auto;">
            </div>
            <div style="height: 50px;text-align: center;">
	    		<button class="btn btn-info btn-sm glyphicon glyphicon-ok-circle" style="margin: 10px 30px 0 0;" onclick=saveOtherPower()>确定</button>
	         	<button class="btn btn-info btn-sm glyphicon glyphicon-remove-circle" style="margin: 10px 0 0 0;" onclick=hidemodel()>取消</button>
            </div>
	</div>
	
</body>
</html>